package util;

import org.hibernate.*;
import org.hibernate.cfg.*;

@SuppressWarnings("deprecation")
public class HibernateUtil {

private static SessionFactory sessionFactory;

//    static {
//        try {
//            sessionFactory = new AnnotationConfiguration()
//                    .configure("Modelo/hibernate.cfg.xml").buildSessionFactory();
//        } catch (Throwable ex) {
//            // Log exception!
//            throw new ExceptionInInitializerError(ex);
//        }
//    }

    public static Session getSession() throws HibernateException {
        return sessionFactory.openSession();
    }
    
    public static void configurarSessionFactory(String usuario, String password){
    	try {
    		Configuration cfg;
    		
    		cfg = new AnnotationConfiguration().configure("Modelo/hibernate.cfg.xml");
    		cfg.setProperty(Environment.USER, usuario);
    		cfg.setProperty(Environment.PASS, password);
    		
//    		sessionFactory = new AnnotationConfiguration()
//    			.configure("Modelo/hibernate.cfg.xml").buildSessionFactory();
    		
    		sessionFactory = cfg.buildSessionFactory();
    		

      } catch (Throwable ex) {
          // Log exception!
          throw new ExceptionInInitializerError(ex);
      }
    }
}
